package cn.com.nes.mybatis.agent.system.entity;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 抖音权限信息表
 * </p>
 *
 * @author nes
 * @since 2022-08-24
 */
@TableName("user_auth_douyin")
public class UserAuthDouyin extends Model<UserAuthDouyin> {

    private static final long serialVersionUID = 1L;

    /**
     * 抖音用户唯一标识
     */
    @TableId(value = "open_id", type = IdType.INPUT)
    private String openId;
    /**
     * 接口调用凭证
     */
    @TableField("access_token")
    private String accessToken;
    /**
     * access_token接口调用凭证超时时间，单位（秒)
     */
    @TableField("expires_in")
    private Long expiresIn;
    /**
     * 用户刷新access_token
     */
    @TableField("refresh_token")
    private String refreshToken;
    /**
     * refresh_token凭证超时时间，单位（秒)
     */
    @TableField("refresh_expires_in")
    private Long refreshExpiresIn;
    /**
     * 用户授权的作用域(Scope)，使用逗号（,）分隔，开放平台几乎几乎每个接口都需要特定的Scope。
     */
    private String scope;
    /**
     * 创建时间
     */
    @TableField("createTime")
    private Date createTime;
    /**
     * 创建者uid
     */
    @TableField("createUid")
    private Long createUid;
    /**
     * 修改者uid
     */
    @TableField("modifyUid")
    private Long modifyUid;
    /**
     * 修改时间
     */
    @TableField("modifyTime")
    private Date modifyTime;
    /**
     * 是否删除:1:表示删除，0:表示未删除
     */
    private Integer sfsc;

    public UserAuthDouyin() {
    }

    public UserAuthDouyin(JSONObject data) {
        this.openId = data.getString("open_id");
        this.accessToken = data.getString("access_token");
        this.expiresIn = data.getLong("expires_in");
        this.refreshToken = data.getString("refresh_token");
        this.refreshExpiresIn = data.getLong("refresh_expires_in");
        this.scope = data.getString("scope");
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public Long getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public Long getRefreshExpiresIn() {
        return refreshExpiresIn;
    }

    public void setRefreshExpiresIn(Long refreshExpiresIn) {
        this.refreshExpiresIn = refreshExpiresIn;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getCreateUid() {
        return createUid;
    }

    public void setCreateUid(Long createUid) {
        this.createUid = createUid;
    }

    public Long getModifyUid() {
        return modifyUid;
    }

    public void setModifyUid(Long modifyUid) {
        this.modifyUid = modifyUid;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Integer getSfsc() {
        return sfsc;
    }

    public void setSfsc(Integer sfsc) {
        this.sfsc = sfsc;
    }

    public static final String ID = "id";

    public static final String OPEN_ID = "open_id";

    public static final String ACCESS_TOKEN = "access_token";

    public static final String EXPIRES_IN = "expires_in";

    public static final String REFRESH_TOKEN = "refresh_token";

    public static final String REFRESH_EXPIRES_IN = "refresh_expires_in";

    public static final String SCOPE = "scope";

    public static final String CREATETIME = "createTime";

    public static final String CREATEUID = "createUid";

    public static final String MODIFYUID = "modifyUid";

    public static final String MODIFYTIME = "modifyTime";

    public static final String SFSC = "sfsc";

    @Override
    public Serializable pkVal() {
        return this.openId;
    }

    @Override
    public String toString() {
        return "UserAuthDouyin{" +
        ", openId=" + openId +
        ", accessToken=" + accessToken +
        ", expiresIn=" + expiresIn +
        ", refreshToken=" + refreshToken +
        ", refreshExpiresIn=" + refreshExpiresIn +
        ", scope=" + scope +
        ", createTime=" + createTime +
        ", createUid=" + createUid +
        ", modifyUid=" + modifyUid +
        ", modifyTime=" + modifyTime +
        ", sfsc=" + sfsc +
        "}";
    }

    public void updateAuthInfo(JSONObject data) {
        this.openId = data.getString("open_id");
        this.accessToken = data.getString("access_token");
        this.expiresIn = data.getLong("expires_in");
        this.refreshToken = data.getString("refresh_token");
        this.refreshExpiresIn = data.getLong("refresh_expires_in");
        this.scope = data.getString("scope");
    }

    public void setCreateInfo(Long userId, Date operateTime) {
        setCreateUid(userId);
        setCreateTime(operateTime);
        setModifyUid(userId);
        setModifyTime(operateTime);
    }

    public void setModifyInfo(Long userId, Date operateTime) {
        setModifyUid(userId);
        setModifyTime(operateTime);
    }
}
